<template>
  <div>
      <el-row>
          <el-col :span="24" align="right">
              <div style="margin-top:10px">
                <el-button @click="addNewRecord" type="primary">添加监控</el-button>
                <el-input style="width:200px" v-model="filters.videoName" placeholder="请输入监控名称"></el-input>
                <el-button type="primary" icon="search" @click="getVideoInfo">搜索</el-button>
                <el-button type="primary" @click="flushAll">刷新</el-button>
              </div>
              <el-row style="margin-top:20px">
                  <el-col :span="$store.getters.user.userRole=='超级管理员'?3:0">
                      <treeComponent style="margin-top:-52px" @GetNodeValue="GetNodeValue"></treeComponent>
                  </el-col>
                  <el-col :span="$store.getters.user.userRole=='超级管理员'?21:24">
                      <el-table :data="list">
                          <el-table-column v-for="(v,k,i) in props" :key="v.id" :label="labels[i]" align="center">
                              <template scope="scope">
                                  <span  v-if="k!=='url'||k!='longitude'||k!=='latitude'" >
                                      {{scope.row[k]}}
                                  </span>
                              </template>
                          </el-table-column>
                          <el-table-column label="操作" width="200" align="center">
                              <template scope="scope">
                                  <el-button type="text" @click="ckDetail(scope.row.videoID)">查看详情</el-button>
                                  <el-button type="text" @click="editVideo(scope.row.videoID)">编辑</el-button>
                                  <el-button type="text" @click="deleteVideo(scope.row.videoID)">删除</el-button>
                              </template>
                          </el-table-column>
                      </el-table>
                  </el-col>
                  <el-col :span="24" style="margin-top:10px" align="right">
                      <el-pagination layout="prev, pager, next" :total="totalInfo" @current-change="handleCurrentChange">
                      </el-pagination>
                  </el-col>
              </el-row>
          </el-col>
      </el-row>
  </div>
</template>

<script>
import treeComponent from "../../components/common/treeComponent";
import * as api from "@/api/videoManage";
export default {
  components: {
    treeComponent: treeComponent
  },
  data() {
    return {
      filters: {
        videoName: null,
        netGridID: null,
        page: 1,
        pageSize: 10
      },
      list: [
        {
          videoID: "1", //bigint not null auto_increment,
          videoName: "2", //varchar(100),
          videoTypeValue: "3", //'视频类型编码值，如01表示森林监控；02表示交通监控。',
          longitude: "222", //'地理经度信息',
          latitude: "33", //'地理纬度信息',
          videoURL: "123", //'视频流地址URL表示',
          netGridID: "1232", //'网格编号，表示所述网格区域',
          producter: "3213", //'生产厂家',
          remarks: "3213" //'备注',
        },
        {
          videoID: "1", //bigint not null auto_increment,
          videoName: "2", //varchar(100),
          videoTypeValue: "3", //'视频类型编码值，如01表示森林监控；02表示交通监控。',
          longitude: "222", //'地理经度信息',
          latitude: "33", //'地理纬度信息',
          videoURL: "123", //'视频流地址URL表示',
          netGridID: "1232", //'网格编号，表示所述网格区域',
          producter: "3213", //'生产厂家',
          remarks: "3213" //'备注',
        }
      ],
      totalInfo: 0,
      props: {
        videoID: "", //bigint not null auto_increment,
        videoName: "", //varchar(100),
        videoTypeName: "", //'视频类型编码值，如01表示森林监控；02表示交通监控。',
        netGridName: "", //'网格编号，表示所述网格区域',
        producter: "" //'生产厂家'
      },
      labels: ["编号", "监控名称", "视频类型", "所属网格", "生产厂家"]
    };
  },
  methods: {
    deleteVideo(id) {
      this.$confirm("是否删除此监控地址, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
          api.deleteVideo(id).then(res => {
            if (res.data) {
              this.$message({
                type: "success",
                message: "删除成功!"
              });
              this.getVideoInfo()
            } else {
              this.$message({
                type: "error",
                message: res.message
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    flushAll() {
      this.filters.videoName = null;
      this.getVideoInfo();
    },
    handleCurrentChange(val) {
      this.filters.page = val;
      this.getVideoInfo();
    },
    ckDetail(id) {
      this.$router.push({ path: "videoInfo", query: { id: id } });
    },
    addNewRecord() {
      this.$router.push("addVideo");
    },
    GetNodeValue(val) {
      this.filters.netGridID = val;
      this.getVideoInfo();
    },
    editVideo(id) {
      this.$router.push({ path: "editVideo", query: { id: id } });
    },
    getVideoInfo() {
      api.fetchVideoInfo(this.filters).then(res => {
        this.list = res.data.vos;
        this.totalInfo = res.data.page.totalCount;
      });
    }
  },
  mounted() {
    if(this.$store.getters.user.userRole!='超级管理员')
      this.filters.netGridID = this.$store.getters.user.netGridID
    this.getVideoInfo();
  }
};
</script>


<style scoped>

</style>
